// Copyright Epic Games, Inc. All Rights Reserved.

#include "HitMarkerConfirmationWidget.h"

#include "Blueprint/UserWidget.h"
#include "SHitMarkerConfirmationWidget.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(HitMarkerConfirmationWidget)

class SWidget;

/**
 * 构造函数
 * @param ObjectInitializer 对象初始化器
 */
UHitMarkerConfirmationWidget::UHitMarkerConfirmationWidget(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	SetVisibility(ESlateVisibility::HitTestInvisible); //设置可见性为命中测试不可见
	bIsVolatile = true; //设置为易变
	AnyHitsMarkerImage.DrawAs = ESlateBrushDrawType::NoDrawType; //设置任意命中标记图像绘制类型为不绘制
}

/**
 * 释放Slate资源
 * @param bReleaseChildren 是否同时释放子资源
 */
void UHitMarkerConfirmationWidget::ReleaseSlateResources(bool bReleaseChildren)
{
	Super::ReleaseSlateResources(bReleaseChildren); //调用父类释放资源

	MyMarkerWidget.Reset(); //重置我的标记控件
}

/**
 * 重新构建控件
 * @return 共享引用到Slate控件
 */
TSharedRef<SWidget> UHitMarkerConfirmationWidget::RebuildWidget()
{
	UUserWidget* OuterUserWidget = GetTypedOuter<UUserWidget>(); //获取外部用户控件
	FLocalPlayerContext DummyContext; //虚拟上下文
	const FLocalPlayerContext& PlayerContextRef = (OuterUserWidget != nullptr) ? OuterUserWidget->GetPlayerContext() : DummyContext; //获取玩家上下文引用

	MyMarkerWidget = SNew(SHitMarkerConfirmationWidget, PlayerContextRef, PerHitMarkerZoneOverrideImages) //创建新的命中标记确认控件
		.PerHitMarkerImage(&(this->PerHitMarkerImage)) //设置每个命中标记图像
		.AnyHitsMarkerImage(&(this->AnyHitsMarkerImage)) //设置任意命中标记图像
		.HitNotifyDuration(this->HitNotifyDuration); //设置命中提示持续时间

	return MyMarkerWidget.ToSharedRef(); //返回共享引用
}